//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "EnergyDailyPosition.h"
using namespace Cephei::QL::Experimental::Commodities;
#undef HANDLE
#undef ABSTRACT
#define STRUCT
Cephei::QL::Experimental::Commodities::CEnergyDailyPosition::CEnergyDailyPosition (DateTime date, Double payLegPrice, Double receiveLegPrice, Boolean unrealized) 
{
	_pSpinlock = new boost::detail::spinlock ();
    try
    {
#ifdef HANDLE
        _phEnergyDailyPosition = NULL;
#endif
        QuantLib::Date _date = (QuantLib::Date)ValueHelper::Convert (date);
        QuantLib::Real _payLegPrice = (QuantLib::Real)ValueHelper::Convert (payLegPrice);
        QuantLib::Real _receiveLegPrice = (QuantLib::Real)ValueHelper::Convert (receiveLegPrice);
        bool _unrealized = (bool)ValueHelper::Convert (unrealized);
        _ppEnergyDailyPosition = new boost::shared_ptr<QuantLib::EnergyDailyPosition> (new QuantLib::EnergyDailyPosition ( _date,  _payLegPrice,  _receiveLegPrice,  _unrealized ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Experimental::Commodities::CEnergyDailyPosition::CEnergyDailyPosition () 
{
	_pSpinlock = new boost::detail::spinlock ();
    try
    {
#ifdef HANDLE
        _phEnergyDailyPosition = NULL;
#endif
        _ppEnergyDailyPosition = new boost::shared_ptr<QuantLib::EnergyDailyPosition> (new QuantLib::EnergyDailyPosition ( ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Experimental::Commodities::CEnergyDailyPosition::CEnergyDailyPosition (boost::shared_ptr<QuantLib::EnergyDailyPosition>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phEnergyDailyPosition = NULL;
#endif
	_ppEnergyDailyPosition = &childNative;
    
}
Cephei::QL::Experimental::Commodities::CEnergyDailyPosition::CEnergyDailyPosition (QuantLib::EnergyDailyPosition& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phEnergyDailyPosition = NULL;
#endif
	_ppEnergyDailyPosition = new boost::shared_ptr<QuantLib::EnergyDailyPosition> (&childNative);
    
    _EnergyDailyPositionOwner = owner;
    
}

Cephei::QL::Experimental::Commodities::CEnergyDailyPosition::CEnergyDailyPosition (CEnergyDailyPosition^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phEnergyDailyPosition = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppEnergyDailyPosition = new boost::shared_ptr<QuantLib::EnergyDailyPosition> (copy->GetShared());
        
    }
}
Cephei::QL::Experimental::Commodities::CEnergyDailyPosition::CEnergyDailyPosition (System::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phEnergyDailyPosition = NULL;
#endif
	if (!t->IsSubclassOf(CEnergyDailyPosition::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Experimental::Commodities::CEnergyDailyPosition::CEnergyDailyPosition (QuantLib::Handle<QuantLib::EnergyDailyPosition>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phEnergyDailyPosition = &childNative;
	_ppEnergyDailyPosition = &static_cast<boost::shared_ptr<QuantLib::EnergyDailyPosition>>(childNative.currentLink());
    
    _EnergyDailyPositionOwner = owner;
}
Cephei::QL::Experimental::Commodities::CEnergyDailyPosition::CEnergyDailyPosition (QuantLib::Handle<QuantLib::EnergyDailyPosition> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phEnergyDailyPosition = &childNative;
	_ppEnergyDailyPosition = &static_cast<boost::shared_ptr<QuantLib::EnergyDailyPosition>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Experimental::Commodities::CEnergyDailyPosition::CEnergyDailyPosition (QuantLib::EnergyDailyPosition childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phEnergyDailyPosition = NULL;
#endif
	_ppEnergyDailyPosition = new boost::shared_ptr<QuantLib::EnergyDailyPosition> (new QuantLib::EnergyDailyPosition (childNative));
    
}
#endif

Cephei::QL::Experimental::Commodities::CEnergyDailyPosition::~CEnergyDailyPosition ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppEnergyDailyPosition != NULL)
    {
	    delete _ppEnergyDailyPosition;
        _ppEnergyDailyPosition = NULL;
    }
}
Cephei::QL::Experimental::Commodities::CEnergyDailyPosition::!CEnergyDailyPosition ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppEnergyDailyPosition != NULL)
    {
	    delete _ppEnergyDailyPosition;
    }
}
QuantLib::EnergyDailyPosition& Cephei::QL::Experimental::Commodities::CEnergyDailyPosition::GetReference ()
{
    if (_ppEnergyDailyPosition == NULL) throw gcnew NativeNullException ();
	return **_ppEnergyDailyPosition;
}
boost::shared_ptr<QuantLib::EnergyDailyPosition>& Cephei::QL::Experimental::Commodities::CEnergyDailyPosition::GetShared ()
{
    if (_ppEnergyDailyPosition == NULL) throw gcnew NativeNullException ();
	return *_ppEnergyDailyPosition;
}
QuantLib::EnergyDailyPosition* Cephei::QL::Experimental::Commodities::CEnergyDailyPosition::GetPointer ()
{
    if (_ppEnergyDailyPosition == NULL) throw gcnew NativeNullException ();
	return &**_ppEnergyDailyPosition;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::EnergyDailyPosition>& Cephei::QL::Experimental::Commodities::CEnergyDailyPosition::GetHandle ()
{
	if (_phEnergyDailyPosition == NULL)
	{
		_phEnergyDailyPosition = new Handle<QuantLib::EnergyDailyPosition> (*_ppEnergyDailyPosition);
	}
	return *_phEnergyDailyPosition;
}
#endif
bool Cephei::QL::Experimental::Commodities::CEnergyDailyPosition::HasNative () 
{
	return (_ppEnergyDailyPosition != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Experimental::Commodities::IEnergyDailyPosition^ Cephei::QL::Experimental::Commodities::CEnergyDailyPosition_Factory::Create (DateTime date, Double payLegPrice, Double receiveLegPrice, Boolean unrealized)
{
    return gcnew CEnergyDailyPosition ( date,  payLegPrice,  receiveLegPrice,  unrealized);
}
Cephei::QL::Experimental::Commodities::IEnergyDailyPosition^ Cephei::QL::Experimental::Commodities::CEnergyDailyPosition_Factory::Create ()
{
    return gcnew CEnergyDailyPosition ();
}
